package csa_testhelper

import (
	"git.sr.ht/~mil/mobroute/src/db"
	"sort"
)

func MapMerge(a, b map[string]uint) map[string]uint {
	r := map[string]uint{}
	for k, v := range a {
		r[k] = v
	}
	for k, v := range b {
		r[k] = v
	}
	return r
}

func ExtractMapConnPtrsToIDs(m map[string]*db.Connection) map[string]string {
	r := map[string]string{}
	for k, v := range m {
		r[k] = v.ConnID
	}
	return r
}

func MapInitialize[TK comparable, TV any](keys []TK, value TV) map[TK]TV {
	r := map[TK]TV{}
	for _, k := range keys {
		r[k] = value
	}
	return r
}

func ReorderByDepartureTime(conns []db.Connection) *[]db.Connection {
	sort.Slice(conns, func(a, b int) bool {
		return conns[a].FromST < conns[b].FromST
	})
	return &conns
}
